﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;

namespace EasyEncryption
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Encryptor encryptor;

            if (radDES.Checked)
            {
                encryptor = new Encryptor(new DESCryptoServiceProvider());
            }
            else if (radRC.Checked)
            {
                encryptor = new Encryptor(new RC2CryptoServiceProvider());
            }
            else if (radRij.Checked)
            {
                encryptor = new Encryptor(new RijndaelManaged());
            }
            else if (radTripDES.Checked)
            {
                encryptor = new Encryptor(new TripleDESCryptoServiceProvider());
            }
            else
            {
                encryptor = new Encryptor(new RC2CryptoServiceProvider());
            }

            var fileContent = System.IO.File.ReadAllLines(textBox1.Text);
            StringBuilder encryptedContent = new StringBuilder();
            for (int i = 0; i < fileContent.Length; i++)
            {
                 File.WriteAllBytes(textBox1.Text,encryptor.EncryptTextToMemory(fileContent[i], Convert.FromBase64String("AAECAwQFBgcICQoLDA0ODw==").ToString(), textBox2.Text));
            }
          

            MessageBox.Show("Done");

        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult result = fd.ShowDialog();
            if (result == DialogResult.OK)
            {
                textBox1.Text = fd.FileName;
            }

        }

        private void decrypt_Click(object sender, EventArgs e)
        {

            Encryptor encryptor;

            if (radDES.Checked)
            {
                encryptor = new Encryptor(new DESCryptoServiceProvider());
            }
            else if (radRC.Checked)
            {
                encryptor = new Encryptor(new RC2CryptoServiceProvider());
            }
            else if (radRij.Checked)
            {
                encryptor = new Encryptor(new RijndaelManaged());
            }
            else if (radTripDES.Checked)
            {
                encryptor = new Encryptor(new TripleDESCryptoServiceProvider());
            }
            else
            {
                encryptor = new Encryptor(new RC2CryptoServiceProvider());
            }


            var fileContent = System.IO.File.ReadAllLines(textBox1.Text);
            Byte[] encryptedContent = new Byte[0];
            for (int i = 0; i < fileContent.Length; i++)
            {
                encryptedContent.Concat(encryptor.DecryptString(fileContent[i], "I'm Awesome", textBox2.Text));
            }
            File.WriteAllBytes(textBox1.Text, encryptedContent);


            MessageBox.Show("Done");
        }
    }


}

